package com.learning.spring.security.pwd.store.config;

import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * ClassName: PasswordEncoderSecurityConfig
 * Description: 密码编码器
 * Date: 2022/7/29 22:45
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class PasswordEncoderSecurityConfig {

    /**
     * 自定义密码编码器
     * <p>
     * 格式为 {id}encodedPassword，其中id为编码的类型，如
     * {bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
     * {noop}123456
     * {sha256}97cde38028ad898ebc02e690819fa220e88c62e0699403e94fff291cfffaf8410849f27605abcbc0
     *
     * 默认创建了密码编码器的集合 PasswordEncoderFactories#createDelegatingPasswordEncoder()
     *
     *
     * @return
     */
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}
